package modle;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * Member entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see modle.Member
 * @author MyEclipse Persistence Tools
 */

public class MemberDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(MemberDAO.class);
	// property constants
	public static final String IP_ADDRESS = "ipAddress";
	public static final String MEMBER_NAME = "memberName";
	public static final String INTERNATIONAL_NAME = "internationalName";
	public static final String MEMBER_GIVEN_NAME = "memberGivenName";
	public static final String MEMBER_FAMILY_NAME = "memberFamilyName";
	public static final String SYSTEM_SECURITY_LEVEL = "systemSecurityLevel";
	public static final String LANGUAGE_CODE = "languageCode";
	public static final String COUNTRY_CODE = "countryCode";
	public static final String PROVINCE_CODE = "provinceCode";
	public static final String CITY_CODE = "cityCode";
	public static final String LOCATION = "location";
	public static final String DESCRIPTION = "description";
	public static final String CATEGORY_CODE1 = "categoryCode1";
	public static final String CATEGORY_CODE2 = "categoryCode2";
	public static final String CATEGORY_CODE3 = "categoryCode3";
	public static final String CATEGORY_CODE4 = "categoryCode4";
	public static final String SUPER_MEMBERSHIP = "superMembership";
	public static final String TICK_VERIFIED = "tickVerified";
	public static final String TICK_SUSPENDED = "tickSuspended";
	public static final String TICK_HIDDEN = "tickHidden";
	public static final String USER_CR = "userCr";
	public static final String USER_MOD = "userMod";

	public void save(Member transientInstance) {
		log.debug("saving Member instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Member persistentInstance) {
		log.debug("deleting Member instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Member findById(java.lang.Integer id) {
		log.debug("getting Member instance with id: " + id);
		try {
			Member instance = (Member) getSession().get("modle.Member", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Member instance) {
		log.debug("finding Member instance by example");
		try {
			List results = getSession().createCriteria("modle.Member").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Member instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Member as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByIpAddress(Object ipAddress) {
		return findByProperty(IP_ADDRESS, ipAddress);
	}

	public List findByMemberName(Object memberName) {
		return findByProperty(MEMBER_NAME, memberName);
	}

	public List findByInternationalName(Object internationalName) {
		return findByProperty(INTERNATIONAL_NAME, internationalName);
	}

	public List findByMemberGivenName(Object memberGivenName) {
		return findByProperty(MEMBER_GIVEN_NAME, memberGivenName);
	}

	public List findByMemberFamilyName(Object memberFamilyName) {
		return findByProperty(MEMBER_FAMILY_NAME, memberFamilyName);
	}

	public List findBySystemSecurityLevel(Object systemSecurityLevel) {
		return findByProperty(SYSTEM_SECURITY_LEVEL, systemSecurityLevel);
	}

	public List findByLanguageCode(Object languageCode) {
		return findByProperty(LANGUAGE_CODE, languageCode);
	}

	public List findByCountryCode(Object countryCode) {
		return findByProperty(COUNTRY_CODE, countryCode);
	}

	public List findByProvinceCode(Object provinceCode) {
		return findByProperty(PROVINCE_CODE, provinceCode);
	}

	public List findByCityCode(Object cityCode) {
		return findByProperty(CITY_CODE, cityCode);
	}

	public List findByLocation(Object location) {
		return findByProperty(LOCATION, location);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByCategoryCode1(Object categoryCode1) {
		return findByProperty(CATEGORY_CODE1, categoryCode1);
	}

	public List findByCategoryCode2(Object categoryCode2) {
		return findByProperty(CATEGORY_CODE2, categoryCode2);
	}

	public List findByCategoryCode3(Object categoryCode3) {
		return findByProperty(CATEGORY_CODE3, categoryCode3);
	}

	public List findByCategoryCode4(Object categoryCode4) {
		return findByProperty(CATEGORY_CODE4, categoryCode4);
	}

	public List findBySuperMembership(Object superMembership) {
		return findByProperty(SUPER_MEMBERSHIP, superMembership);
	}

	public List findByTickVerified(Object tickVerified) {
		return findByProperty(TICK_VERIFIED, tickVerified);
	}

	public List findByTickSuspended(Object tickSuspended) {
		return findByProperty(TICK_SUSPENDED, tickSuspended);
	}

	public List findByTickHidden(Object tickHidden) {
		return findByProperty(TICK_HIDDEN, tickHidden);
	}

	public List findByUserCr(Object userCr) {
		return findByProperty(USER_CR, userCr);
	}

	public List findByUserMod(Object userMod) {
		return findByProperty(USER_MOD, userMod);
	}

	public List findAll() {
		log.debug("finding all Member instances");
		try {
			String queryString = "from Member";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Member merge(Member detachedInstance) {
		log.debug("merging Member instance");
		try {
			Member result = (Member) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Member instance) {
		log.debug("attaching dirty Member instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Member instance) {
		log.debug("attaching clean Member instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}